<?php
namespace jy_area_fee;
defined('BY_JYA') or exit('error');
/*
	经销插件工具类
*/
class model extends \plugin{
	
	public function create_condition($conditions){
		if(!$conditions){
			return '';
		}
		if(!is_array($conditions)){
			$conditions=json_decode($conditions,true);
		}
		$level_up_types=$this->level_up_types;
		$current_level_up_types=$this->current_level_up_types();
		$str='';
		foreach($current_level_up_types as $key){
			$str.=$level_up_types[$key].'达'.$conditions[$key].';';
		}
		return $str;
	}
	public function current_level_up_types(){
		return str_array($this->setting['level_up_types']);
	}
	public function otherfee_types(){
		$jy_renwushop = check_permission('jy_renwushop');
		$res=array(
			'0'=>'无',
		);
		if($jy_renwushop){
			$res['jy_renwushop']='任务商城分佣';
		}
		return $res;
	}
	public function get_area_code($area){
		if(!$area['province']){
			return '';
		}
		$address=$area['province'];
		if($area['city']){
			$address.=' '.$area['city'];
		}
		if($area['district']){
			$address.=' '.$area['district'];
		}
		if($area['street']){
			$address.=' '.$area['street'];
		}
		$area_code=pdo_getcolumn('core_area',array('address'=>$address),'code');
		if(!$area_code){
			$isup=pdo_count('core_area',array(),'code');
			if($isup==0){
				require ROOT_D.'/update/update_area.php';
			}
		}
		return $area_code;
	}
	public function get_upgoods($goods){
		$member=$this->get_get('member',array('mid'=>$_SESSION['uid']),array('id','mid','agent_id','sale_id'));
		if($member['agent_id']){
			$mygoods=$this->get('mygoods',array('mid'=>$member['agent_id'],'goodsid'=>$goods['id']));
			if(!$mygoods['id']){
				return $goods;
			}
			$goods['total']=$mygoods['total'];
			$goods['price']=$mygoods['price'];
		}
		return $goods;
	}
	/*
		日志信息
	*/
	public function set_log($params,$type=0){
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$params['mid']?:$_SESSION['uid'],
			'dian_mid'=>$params['dian_mid'],
			'msg'=>$params['msg'],
			'type'=>$type,
			'fee'=>$params['fee'],
			'status'=>$params['status'],
			'createtime'=>TIMESTAMP
		);
		$this->pdo_insert('log',$insert);
		return true;
	}
}